package com.gxc.blog.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.gxc.blogm.service.AlbumService;
import com.gxc.blogm.service.ArticleService;
import com.gxc.dbcore.util.PageInfo;

public class IndexController {

	private ArticleService articleService;
	private AlbumService albumService;

	public ArticleService getArticleService() {
		return articleService;
	}

	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}

	public AlbumService getAlbumService() {
		return albumService;
	}

	public void setAlbumService(AlbumService albumService) {
		this.albumService = albumService;
	}

	/**
	 * blog首页面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ModelAndView index(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap model = new HashMap();
		HashMap params = new HashMap();
		PageInfo pageInfo = new PageInfo();

		// 获取最新文章
		params.put("fieldSort", "create_time desc");
		pageInfo.setPageCurrent(1);
		pageInfo.setPageSize(3);
		List articleList = articleService.listPage(params, pageInfo).getList();
		model.put("articleList", articleList);

		// 获取最新图集
		params.clear();
		params.put("type", 1);
		params.put("fieldSort", "create_time desc");
		pageInfo.setPageCurrent(1);
		pageInfo.setPageSize(3);
		List albumList = albumService.listPage(params, pageInfo).getList();
		model.put("albumList", albumList);

		// 获取杂货铺最新物品
		// 暂无

		return new ModelAndView("blog/index.vm", model);
	}

	/**
	 * 关于页面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ModelAndView about(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return new ModelAndView("blog/about.vm");
	}
}
